﻿#region 命名空间

using System;
using System.Collections;
using System.Data;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Web.SessionState;
using WinnerCMS.BLL;
using WinnerCMS.Common;
using WinnerCMS.Model;
using System.Text;

#endregion

namespace WinnerCMS.WebUI
{
    /// <summary>
    ///     $codebehindclassname$ 的摘要说明
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/"), WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    public class AjaxPostBack : IHttpHandler, IReadOnlySessionState
    {
        public void ProcessRequest(HttpContext context)
        {
            context.Response.Expires = 0;
            context.Response.CacheControl = "no-cache";
            context.Response.ContentType = "text/plain";

            if (PostData.PostFormRight() == false)
            {
                context.Response.Write("来源错误。");
                return;
            }

            var action = context.Request["Action"];
            Result res;
            switch (action)
            {
                case "RefurbishTemplates": //刷新网页模板
                    new RefurbishTemplates().RefurbishForAJAX();
                    break;

                case "ShowShopingCart": // 显示购物车
                    var str = new ShoppingCartManage().ShowCartState(4);
                    context.Response.Write(str);
                    break;
                case "LoadShopingCartData": // 显示购物车数据
                    context.Response.Write(new ShoppingCartManage().LoadData().ToJson());
                    break;
                case "ShopingCartDelete": // 
                    res = new ShoppingCartManage().Delete(int.Parse(context.Request["ID"]));
                    context.Response.Write(res.ToJson());
                    break;
                case "JoinCart": // 
                    new ShoppingCartManage().JoinCart(context);
                    break;
                case "EditShoppingCartQuantity": // 
                    res = new ShoppingCartManage().EditShoppingCartQuantity(context);
                    context.Response.Write(res.ToJson());
                    break;
                case "UpDataNews": // 

                    break;
                default:
                    context.Response.Write("参数错误。");
                    SecurityCenterManage.AppErr("Action参数错误。");
                    break;
            }
        }


        public bool IsReusable
        {
            get { return false; }
        }
    }
}